package com.shop.controller;

import com.shop.commom.enums.YesORNo;
import com.shop.commom.utils.JSONResult;
import com.shop.service.CarouselService;
import com.shop.service.CategoryService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = "首页")
@RestController
@RequestMapping("index")
public class IndexController {


    @Autowired
    private CarouselService carouselService;
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/carousel")
    public JSONResult index(){
        return JSONResult.OK(carouselService.queryAll(YesORNo.YES.value));
    }

    @GetMapping("/cats")
    public JSONResult cats(){
        return JSONResult.OK(categoryService.queryAllRootCats());
    }

    @GetMapping("/subCat/{id}")
    public JSONResult cats(@PathVariable Integer id){
        return JSONResult.OK(categoryService.getSubList(id));
    }


    @GetMapping("/sixNewItems/{id}")
    public JSONResult sixNewItems(@PathVariable Integer id){
        return JSONResult.OK(categoryService.querySixNewItemsLazy(id));
    }


}
